package Test;

import java.util.ArrayList;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;

import RPS.Player;
import RPS.RPSEnum;
import RPS.Result;
import RPS.RockPaperScissors;

public class TestRockPaperScissorsTest {
  
  private RockPaperScissors rps;
  
  @DataProvider(name="WIN")
  public Object [][] createWinData() {
      return new Object[][] {
                {RPSEnum.ROCK, RPSEnum.SCISSORS},
                {RPSEnum.SCISSORS, RPSEnum.PAPER},
                {RPSEnum.PAPER, RPSEnum.ROCK}
      } ;
 }
  
  @DataProvider(name="TIE")
  public Object [][] createTieData() {
      return new Object[][] {
                {RPSEnum.ROCK, RPSEnum.ROCK},
                {RPSEnum.SCISSORS, RPSEnum.SCISSORS},
                {RPSEnum.PAPER, RPSEnum.PAPER}
      } ;
 }
  
  @DataProvider(name="LOST")
  public Object [][] createLostData() {
      return new Object[][] {
                {RPSEnum.SCISSORS, RPSEnum.ROCK},
                {RPSEnum.PAPER, RPSEnum.SCISSORS},
                {RPSEnum.ROCK, RPSEnum.PAPER}
      } ;
 }
  
  @DataProvider(name="WIN_Player")
  public Object [][] createWinPlayer() {
	  
	  ArrayList<RPSEnum> m1=new ArrayList<RPSEnum>();
	  ArrayList<RPSEnum> m2=new ArrayList<RPSEnum>();
	  ArrayList<RPSEnum> m3=new ArrayList<RPSEnum>();
	  ArrayList<RPSEnum> m4=new ArrayList<RPSEnum>();
	  ArrayList<RPSEnum> m5=new ArrayList<RPSEnum>();
	  ArrayList<RPSEnum> m6=new ArrayList<RPSEnum>();
	  
	  for(int i=0;i<10;i++){
		  m1.add(RPSEnum.SCISSORS);
		  m2.add(RPSEnum.PAPER);
		  m3.add(RPSEnum.PAPER);
		  m4.add(RPSEnum.ROCK);
		  m5.add(RPSEnum.ROCK);
		  m6.add(RPSEnum.SCISSORS);
	  }
	  
      return new Object[][] {
                {new Player("p1",m1),new Player("p2",m2)},
                {new Player("p1",m3),new Player("p2",m4)},
                {new Player("p1",m5),new Player("p2",m6)}
      } ;
 }
  
  @DataProvider(name="TIE_Player")
  public Object [][] createTiePlayer() {
	  
	  ArrayList<RPSEnum> m1=new ArrayList<RPSEnum>();
	  ArrayList<RPSEnum> m2=new ArrayList<RPSEnum>();
	  ArrayList<RPSEnum> m3=new ArrayList<RPSEnum>();
	  ArrayList<RPSEnum> m4=new ArrayList<RPSEnum>();
	  ArrayList<RPSEnum> m5=new ArrayList<RPSEnum>();
	  ArrayList<RPSEnum> m6=new ArrayList<RPSEnum>();
	  
	  for(int i=0;i<5;i++){
		  m2.add(RPSEnum.SCISSORS);
		  m1.add(RPSEnum.PAPER);
		  m4.add(RPSEnum.PAPER);
		  m3.add(RPSEnum.ROCK);
		  m6.add(RPSEnum.ROCK);
		  m5.add(RPSEnum.SCISSORS);
	  }
	  for(int i=5;i<10;i++){
		  m1.add(RPSEnum.SCISSORS);
		  m2.add(RPSEnum.PAPER);
		  m3.add(RPSEnum.PAPER);
		  m4.add(RPSEnum.ROCK);
		  m5.add(RPSEnum.ROCK);
		  m6.add(RPSEnum.SCISSORS);
	  }
	  
      return new Object[][] {
                {new Player("p1",m1),new Player("p2",m2)},
                {new Player("p1",m3),new Player("p2",m4)},
                {new Player("p1",m5),new Player("p2",m6)}
      } ;
 }
  
  @DataProvider(name="Rand_Player")
  public Object [][] createRandPlayer() {
	  return new Object[][] {
              {new Player("p1"),new Player("p2")},
              {new Player("p1"),new Player("p2")},
              {new Player("p1"),new Player("p2")}
    } ;
  }
  
  @DataProvider(name="LOST_Player")
  public Object [][] createLostPlayer() {
	  
	  ArrayList<RPSEnum> m1=new ArrayList<RPSEnum>();
	  ArrayList<RPSEnum> m2=new ArrayList<RPSEnum>();
	  ArrayList<RPSEnum> m3=new ArrayList<RPSEnum>();
	  ArrayList<RPSEnum> m4=new ArrayList<RPSEnum>();
	  ArrayList<RPSEnum> m5=new ArrayList<RPSEnum>();
	  ArrayList<RPSEnum> m6=new ArrayList<RPSEnum>();
	  
	  for(int i=0;i<10;i++){
		  m2.add(RPSEnum.SCISSORS);
		  m1.add(RPSEnum.PAPER);
		  m4.add(RPSEnum.PAPER);
		  m3.add(RPSEnum.ROCK);
		  m6.add(RPSEnum.ROCK);
		  m5.add(RPSEnum.SCISSORS);
	  }
	  
      return new Object[][] {
                {new Player("p1",m1),new Player("p2",m2)},
                {new Player("p1",m3),new Player("p2",m4)},
                {new Player("p1",m5),new Player("p2",m6)}
      } ;
 }
  
  
  
  @Test(dataProvider="WIN")
  public void testWinPlay(RPSEnum p1,RPSEnum p2) {
	  assert rps.play(p1,p2) == Result.WIN;
  }
  
  @Test(dataProvider="TIE")
  public void testTiePlay(RPSEnum p1,RPSEnum p2) {
	  assert rps.play(p1,p2) == Result.TIE;
  }
  
  @Test(dataProvider="LOST")
  public void testLostPlay(RPSEnum p1,RPSEnum p2) {
	  assert rps.play(p1,p2) == Result.LOST;
  }
  
  @Test(dataProvider="WIN_Player")
  public void testPlayerWin(Player p1,Player p2){
	  Result r=rps.play(p1, p2);
	  assert r==Result.WIN;
  }
  
  @Test(dataProvider="TIE_Player")
  public void testPlayerTie(Player p1,Player p2){
	  Result r=rps.play(p1, p2);
	  assert r==Result.TIE;
  }
  
  @Test(dataProvider="LOST_Player")
  public void testPlayerLost(Player p1,Player p2){
	  Result r=rps.play(p1, p2);
	  assert r==Result.LOST;
  }
  
  @BeforeClass
  public void setUpClass() {
	  rps=new RockPaperScissors();
  }

  @AfterClass
  public void tearDownClass() {
	  rps=null;
  }

}
